package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.SnListBean;

import java.util.List;

public class SnlistAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<SnListBean> mSnListBean;
    private String TAG="AgentAdapter";
    public SnlistAdapter(Context context, List<SnListBean> maxSnListBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mSnListBean = maxSnListBeanDatas;
    }
    @Override
    public int getCount() {
        return mSnListBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mSnListBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.snlist_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.mSN = convertView.findViewById(R.id.sn_number);
            viewHolder.mCh = convertView.findViewById(R.id.sn_select);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        SnListBean snListBean = mSnListBean.get(position);
        viewHolder.mSN.setText(snListBean.getSn());
        if (mSnListBean.get(position).isChecked()) {
            viewHolder.mCh.setImageResource(R.drawable.cb_true);
        }else {
            viewHolder.mCh.setImageResource(R.drawable.cb_fase);
        }
         return convertView;
    }



    public static class ViewHolder{
        TextView mSN;
        ImageView mCh;
    }


}
